package message_type

import (
	"gitee.com/xlizy/common-go/base/enums"
	"strconv"
)

type MessageType int

const (
	Notice MessageType = iota + 1
	Activity
	PersonalMessage
)

func (e MessageType) Code() int32 {
	return int32(e)
}

func (e MessageType) Des() string {
	return enums.BE(e).Des
}

func (e MessageType) Enum() string {
	return enums.BE(e).Enum
}

func (e MessageType) Val() int {
	return int(e)
}
func (e *MessageType) UnmarshalJSON(value []byte) error {
	*e = MessageType(enums.UnmarshalEnum(value))
	return nil
}

func (e MessageType) MarshalJSON() ([]byte, error) {
	switch e {
	case Notice:
		return enums.JsonObj(int(e), "Notice", "系统公告")
	case Activity:
		return enums.JsonObj(int(e), "Activity", "活动通知")
	case PersonalMessage:
		return enums.JsonObj(int(e), "PERSONAL_MESSAGE", "个人消息")
	}
	return []byte(strconv.Itoa(int(e))), nil
}

func SelectOptions() []enums.SelectOptions {
	return enums.ToSelectOptions([]any{Notice, Activity, PersonalMessage})
}
